<template>
  <div class="login">
    <form @submit.prevent="login">
      <input type="text" v-model="username" placeholder="用户名" />
      <input type="password" v-model="password" placeholder="密码" />
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  name: 'MainLogin', // 修改组件名称为多词形式
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    login() {
      const user = { username: this.username, password: this.password };
      this.$store.dispatch('login', user).then(() => {
        this.$router.push({ name: 'Dashboard' });
      });
    },
  },
};
</script>

<style>
/* 样式代码 */
</style>
